package edu.drexel.jrexel2d.networking;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.SocketException;

import edu.drexel.jrexel2d.networking.socket.GameClientSocket;
import edu.drexel.jrexel2d.networking.socket.GameSocket;

public class NetworkClient {
	private int byteSize;
	private GameSocket gameSocket;

	public GameSocket getGameSocket() {
		return gameSocket;
	}

	private GamePacket receivePacket;

	// implement queue
	public NetworkClient(InetAddress ip, int port, int byteSize)
			throws SocketException {
		this.gameSocket = new GameClientSocket(ip, port);
		this.byteSize = byteSize;
	}

	public void sendSerializable(Serializable data) {
		byte[] sendDataArray = new byte[byteSize];
		sendDataArray = Serializer.serializeSerializable(data);
		GamePacket sendPacket = new GamePacket(sendDataArray,
				sendDataArray.length, gameSocket.getIp(), gameSocket.getPort());
		gameSocket.send(sendPacket);
	}

	public byte[] getData() {
		byte[] data = receivePacket.getData();
		return data;
	}

	public Boolean receivePacket() {
		receivePacket = new GamePacket(byteSize);
		return gameSocket.receive(receivePacket);

	}

	public GamePacket getPacket() {

		return receivePacket;
	}
}
